﻿using System;
using System.Collections.Generic;

namespace mki.Backup.GUI.Helper
{
	internal static class LinqExtension
	{
		/// <summary>
		/// Descendantses the specified source.
		/// </summary>
		/// <typeparam name="T"></typeparam>
		/// <param name="source">The source.</param>
		/// <param name="descendBy">The descend by.</param>
		/// <returns></returns>
		public static IEnumerable<T> Descendants<T>(this IEnumerable<T> source, Func<T, IEnumerable<T>> descendBy)
		{
			foreach (var value in source)
			{
				yield return value;

				foreach (var child in descendBy(value).Descendants(descendBy))
				{
					yield return child;
				}
			}
		}
	}
}
